import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
import * as evbApi from '/@/api/infra/eventBus';
const { t } = useI18n('');

export enum MsgFieldType {
  ARRAY = 'array',
  OBJECT = 'object',
  BASE = 'base'
}


export const msgFieldColumns : BasicColumn[] = [
  {
    title: t('名称'),
    dataIndex: 'fieldName',
    align: 'left',
    customRender: ({ text, record }) => {
      if (record.fieldKey == 'ITEMS') {
        return render.renderTag(text, 'green')
      }
      return `${record.fieldName}（${record.fieldKey}）`
    },
    width: 230,
  },
  {
    title: t('类型'),
    dataIndex: 'fieldType',
    width: 80,
  },
]
export const columns: BasicColumn[] = [
  {
    title: t('发布者名称'),
    dataIndex: 'publisherName',
    width: 160,
  },
  {
    title: t('发布者标识'),
    dataIndex: 'publisherCode',
    width: 160,
  },
  {
    title: t('主题标识'),
    dataIndex: 'code',
    width: 160,
  },
  {
    title: t('主题名称'),
    dataIndex: 'name',
    width: 160,
  },
  {
    title: t('创建时间'),
    dataIndex: 'createdAt',
    width: 150,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('发布者'),
    field: 'publisherCode',
    component: 'ApiSelect',
    componentProps: {
      api: evbApi.listPublisher,
      showSearch: true,
      allowClear: true,
      labelField: 'name',
      valueField: 'code',
    },
  },
  {
    label: t('主题名称'),
    field: 'name',
    component: 'Input',
  },
  {
    label: t('主题标识'),
    field: 'code',
    component: 'Input',
  },
];

export const fieldFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'topicCode',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'parentId',
    component: 'Input',
    defaultValue: null,
    show: false,
  },
  {
    label: t('字段名称'),
    required: true,
    field: 'fieldName',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return values.fieldKey == 'ITEMS'
    },
    componentProps: {
      maxlength: 300,
    },

  },
  {
    label: t('字段标识'),
    required: true,
    field: 'fieldKey',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    componentProps: {
      maxlength: 300,
    },
  },
  {
    label: t('字段类型'),
    field: 'fieldType',
    required: true,
    defaultValue: null,
    component: "JDictSelectTag",
  }
];


export const inputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: t('主题名称'),
    required: true,
    field: 'name',
    component: 'Input',
    componentProps: {
      maxlength: 300,
    },

  },
  {
    label: t('主题标识'),
    required: true,
    field: 'code',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    componentProps: {
      maxlength: 300,
    },
  },
  {
    label: t('发布者'),
    required: true,
    field: 'publisherCode',
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    component: 'ApiSelect',
    componentProps: {
      api: evbApi.listPublisher,
      showSearch: true,
      allowClear: true,
      labelField: 'name',
      valueField: 'code',
    },
  },
  {
    label: t('说明'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
      autoSize: {
        minRows: 4,
        maxRows: 8,
      },
    },
    colProps: { lg: 24, md: 24 },
  },
];


export const formDetailSchema: DescItem[] = [
  {
    label: t('发布者名称'),
    field: 'publisherName'
  },
  {
    label: t('发布者标识'),
    field: 'publisherCode'
  },
  {
    label: t('主题名称'),
    field: 'name'
  },
  {
    label: t('主题标识'),
    field: 'code'
  },
  {
    label: t('说明'),
    labelMinWidth: 40,
    field: 'remark'
  },
  {
    label: t('创建时间'),
    field: 'createdAt'
  },
  {
    label: t('创建者'),
    field: 'createdBy'
  },
  {
    label: t('更新时间'),
    field: 'updatedAt'
  },
  {
    label: t('更新者'),
    field: 'updatedBy'
  },
];
